package com.familytree.repository;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.familytree.model.Relationship;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface RelationshipRepository extends BaseMapper<Relationship> {
    
    @Select("SELECT * FROM relationships WHERE member_id = #{memberId}")
    List<Relationship> findByMemberId(Long memberId);
    
    @Select("SELECT * FROM relationships WHERE related_member_id = #{memberId} AND relationship_type = 'spouse' LIMIT 1")
    Relationship findSpouseRelationship(Long memberId);
    
    @Select("SELECT * FROM relationships WHERE related_member_id = #{childId} AND relationship_type = 'child' LIMIT 1")
    Relationship findParentRelationship(Long childId);

    @Select("SELECT * FROM relationships WHERE member_id = #{memberId} AND relationship_type = #{type}")
    List<Relationship> findByMember1IdAndType(Long memberId, String type);
} 